<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/taglib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <title>教授课程</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入bootstrap -->
    <link rel="stylesheet" type="text/css" href="${ctx}/css/bootstrap.min.css">
    <!-- 引入JQuery  bootstrap.js-->
    <script src="${ctx}/js/jquery-3.2.1.min.js"></script>
    <script src="${ctx}/js/bootstrap.min.js"></script>

</head>
<body>
<!-- 顶栏 -->
<jsp:include page="top.jsp"/>
<!-- 中间主体 -->
<div class="container" id="content">
    <div class="row">
        <jsp:include page="menu.jsp"/>
        <div class="col-md-10">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="row">
                        <h1 class="col-md-5">课程签到</h1>
                        <%--							<form class="bs-example bs-example-form col-md-5" role="form" style="margin: 20px 0 10px 0;" action="${ctx}/teacher/findCourse" id="form1" method="post">--%>
                        <%--								<div class="input-group">--%>
                        <%--									<input type="text" class="form-control" placeholder="请输入课程名" name="name">--%>
                        <%--									<span class="input-group-addon btn" onclick="document.getElementById('form1').submit" id="sub">搜索</span>--%>
                        <%--								</div>--%>
                        <%--							</form>--%>

                    </div>
                </div>
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>课程号</th>
                        <th>课程名称</th>
                        <th>总人数</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${courseList}" var="item">
                        <tr>
                            <td>${item.id}</td>
                            <td>${item.name}</td>
                            <td>${item.num}</td>
                            <td>
                                <c:if test="${item.state=='false'}">
                                    <button id="signIn" class="btn btn-danger btn-xs btn-info"
                                            disabled="disabled"
                                            onclick="aa(${item.id})">发起签到
                                    </button>
                                </c:if>
                                <c:if test="${item.state=='true'}">
                                    <button id="signIn" class="btn btn-danger btn-xs btn-info"
                                            onclick="aa(${item.id})">发起签到
                                    </button>
                                </c:if>
                                <button class="btn btn-default btn-xs btn-info"
                                        onClick="location.href='${ctx}/signIn/list?id=${item.id}'">历史记录
                                </button>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <div class="panel-footer">
                    <c:if test="${pagingVO != null}">
                        <nav style="text-align: center">
                            <ul class="pagination">
                                <li><a href="${ctx}/student/showCourse?page=${pagingVO.upPageNo}">&laquo;上一页</a></li>
                                <li class="active"><a href="">${pagingVO.curentPageNo}</a></li>
                                <c:if test="${pagingVO.curentPageNo+1 <= pagingVO.totalCount}">
                                    <li>
                                        <a href="${ctx}/student/showCourse?page=${pagingVO.curentPageNo+1}">${pagingVO.curentPageNo+1}</a>
                                    </li>
                                </c:if>
                                <c:if test="${pagingVO.curentPageNo+2 <= pagingVO.totalCount}">
                                    <li>
                                        <a href="${ctx}/student/showCourse?page=${pagingVO.curentPageNo+2}">${pagingVO.curentPageNo+2}</a>
                                    </li>
                                </c:if>
                                <c:if test="${pagingVO.curentPageNo+3 <= pagingVO.totalCount}">
                                    <li>
                                        <a href="${ctx}/student/showCourse?page=${pagingVO.curentPageNo+3}">${pagingVO.curentPageNo+3}</a>
                                    </li>
                                </c:if>
                                <c:if test="${pagingVO.curentPageNo+4 <= pagingVO.totalCount}">
                                    <li>
                                        <a href="${ctx}/student/showCourse?page=${pagingVO.curentPageNo+4}">${pagingVO.curentPageNo+4}</a>
                                    </li>
                                </c:if>
                                <li><a href="${ctx}/student/showCourse?page=${pagingVO.totalCount}">最后一页&raquo;</a></li>
                            </ul>
                        </nav>
                    </c:if>
                </div>
            </div>

        </div>
    </div>
</div>
<div class="container" id="footer">
    <div class="row">
        <div class="col-md-12"></div>
    </div>
</div>
</body>
<script type="text/javascript">

    function aa(signInId) {
        var data = {
            // "receiverName":$("#receiverName option:selected").val()
            "signInId": signInId
        }
        console.log(signInId)
        $.ajax({
            type: "POST",
            url: "${ctx}/signIn/submit",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                if (data.flag == "ok") {
                    location.href = "index";
                } else {
                    alert("提交成功!");
                    location.reload();
                }

            }
        })
    }

    <%--设置菜单中--%>
    $("#nav li:nth-child(3)").addClass("active")
    <c:if test="${pagingVO != null}">
    if (${pagingVO.curentPageNo} == ${pagingVO.totalCount}) {
        $(".pagination li:last-child").addClass("disabled")
    }
    ;

    if (${pagingVO.curentPageNo} == ${1}) {
        $(".pagination li:nth-child(1)").addClass("disabled")
    }
    ;
    </c:if>

    $("#sub").click(function () {
        $("#form1").submit();
    });
</script>
</html>